package com.yinile.zc03.web;

import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yinile.zc03.domain.Author;
import com.yinile.zc03.service.AuthorService;
import com.yinile.zc03.sys.result.BaseResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;

/**
 * 作者
 * @author jyn
 * 
 */
@RestController
@RequestMapping("/author")
@Api(description="Author，作者相关")
public class AuthorController {
	@Autowired
	AuthorService authorService;
	
	@ApiOperation(value = "作者分页", notes = "作者分页", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="/page",method=RequestMethod.GET)
	public BaseResult page(Integer offset, Integer step, String name, String address) {
		return this.authorService.findByPage(offset, step, name, address);
	}
	
	@ApiOperation(value = "保存作者", notes = "保存作者,生日是毫秒数", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="",method=RequestMethod.POST)
	public BaseResult save(@RequestBody Author author){
		return this.authorService.save(author);
	}
	
	@ApiOperation(value = "作者详情", notes = "作者详情", 
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public BaseResult get(@PathVariable String id){
		return this.authorService.findById(id);
	}
	
	@ApiOperation(value = "更新作者", notes = "更新作者", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="",method=RequestMethod.PUT)
	public BaseResult update(@RequestBody Author author){
		return this.authorService.update(author);
	}
	
	@ApiOperation(value = "删除作者", notes = "删除作者", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public BaseResult delete(@PathVariable String id){
		return this.authorService.delete(id);
	}
	
}
